package com.youcash.ZyWallet_spring.controller;

import com.youcash.ZyWallet_spring.entity.CustomersInfo;

import com.youcash.ZyWallet_spring.service.CustomersInfoService;
import com.youcash.ZyWallet_spring.vo.ResStatus;
import com.youcash.ZyWallet_spring.vo.ResultVO;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Zhangzifeng
 */
@RestController
@RequestMapping("/customers")
@Api(value = "提供鸿蒙端用户的登录和注册接口", tags = "用户管理")
@CrossOrigin
public class CustomersInfoController {

    @Resource
    private CustomersInfoService customersInfoService;

    //方法注解：说明接口方法的作用
    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "phone", value = "用户登录手机号", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "password", value = "用户登录密码", required = true),
    })
    @PostMapping("/login")
    public ResultVO login(@RequestParam("phone") String phone,
                          @RequestParam(value = "password") String pwd) {
        return customersInfoService.checkLogin(phone, pwd);
    }

    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "phone", value = "用户注册手机号", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "password", value = "用户注册密码", required = true),
    })
    @PostMapping("/register")
    public ResultVO register(@RequestBody CustomersInfo customersInfo) {
        return customersInfoService.customersRegister(customersInfo.getPhone(), customersInfo.getPassword());
    }

    @ApiOperation("查询手机号接口")
    //方法注解：说明接口方法的参数
    @ApiImplicitParam(dataType = "string", name = "phone", value = "用户手机号", required = true)
    @GetMapping("/getByPhone")
    public ResultVO getByPhone(@RequestParam("phone") String phone) {
        return customersInfoService.getByPhone(phone);
    }

    @ApiOperation("查询个人信息接口")
    //方法注解：说明接口方法的参数
    @ApiImplicitParam(dataType = "Integer", name = "id", value = "用户id", required = true)
    @GetMapping("/getById")
    public ResultVO getById(@RequestParam("id") Integer id) {
        return customersInfoService.getById(id);
    }

    @ApiOperation("用于实名认证的接口")
    @PutMapping("/updateInfo/{id}")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "name", value = "用户姓名", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "idNum", value = "用户身份证号码", required = true),
            @ApiImplicitParam(
                    dataType = "string", name = "sex", value = "用户性别", required = true)
    })
    public ResultVO updateInfo(@PathVariable("id") Integer id,
                              @RequestParam("name") String name,
                              @RequestParam("idNum") String idNum,
                              @RequestParam("sex") String sex){
        return customersInfoService.updateInfo(id, name, idNum, sex);
    }

    @ApiOperation("校验token是否过期")
    @GetMapping("/check")
    public ResultVO checkToken(@RequestHeader("token") String token){
        return new ResultVO(ResStatus.OK,"success",null);
    }

    @PutMapping("/updatePwd")
    @ApiOperation("通过手机号码更新密码")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "String", name = "phone", value = "用户手机号码", required = true),
            @ApiImplicitParam(
                    dataType = "String", name = "password", value = "密码", required = true)
    })
    public ResultVO updateStatusById(@RequestParam("phone") String phone,
                                     @RequestParam("password") String password) {
        return customersInfoService.updatePwdByPhone(phone, password);
    }
}
